import type { Router } from 'vue-router'
import { useAppStore } from '@/store'
import { getFormatDynamicRouter } from '@/utils/common/dynamic-router'

//首页
import home from '@/layout/index.vue'

import { isLogin } from '@/utils/common/auth'
import useSellerRegisterStore from '@/store/modules/register'

import type { LocationQueryRaw } from 'vue-router'

/**
 * 添加动态路由/解决动态路由页面刷新白屏问题
 * @param router
 */
export default function useStoreRegistortGuard(router: Router) {
  router.beforeEach(async (to, from, next) => {
    const app = useAppStore()
    const { registerQualification, registerShop } = useSellerRegisterStore()

    if (to.path === '/404') {
      next()
    }
    const pathList = [registerQualification, registerShop]

    if (pathList.includes(to.path)) {
      if (useSellerRegisterStore().isRouterNext[to.path]) {
        next()
      } else {
        //重定向到登入页面
        next({
          path: '/404',
        })
      }
    } else {
      next()
    }
  })
}
